package process_demo.review.about_review.join;

import java.util.Arrays;

/**
 * @author haomin
 * @date 2022/09/09 09:12
 **/
public class ConcurrentSort {
    static class SortWorker extends Thread {
        private final long[] array;
        private final int fromIndex;
        private final int toIndex;

        SortWorker(long[] array, int fromIndexm, int toIndex){
            this.array = array;
            this.fromIndex = fromIndexm;
            this.toIndex = toIndex;
        }

        @Override
        public void run() {
            Arrays.sort(array, fromIndex, toIndex);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        long[] array = ArrayHelper.generateArray(4000_0000);
        long s = System.currentTimeMillis();

        Thread t1 = new SortWorker(array, 0, 1000_0000);
        t1.start();

        Thread t2 = new SortWorker(array, 1000_0000, 2000_0000);
        t2.start();

        Thread t3 = new SortWorker(array, 2000_0000, 3000_0000);
        t3.start();

        Thread t4 = new SortWorker(array, 3000_0000, 4000_0000);
        t4.start();

        t1.join();
        t2.join();
        t3.join();
        t4.join();

        long e = System.currentTimeMillis();
        System.out.println(e-s);
    }
}